export default {
  methods: {
    // 自定义合计行
    // this.sumArr = [prop] 指定列合计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        const values = data.map(item => Number(item[column.property]))
        if (!values.every(value => isNaN(value)) && this.sumArr.includes(column.property)) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return (Number(prev) + Number(curr)).toFixed(2)
            } else {
              return prev
            }
          }, 0)
        } else {
          sums[index] = ''
        }
      })
      sums.forEach((res, index) => {
        sums[index] = Number(sums[index]).toLocaleString()
        if (sums[index] <= 0) {
          sums[index] = ''
        }
      })
      sums[0] = '合计'
      return sums
    },
    // 方案 -- 自定义列表
    customHandle1(ev) {
      this.tableHeaders = []
      if (ev.header && ev.header.length > 0) {
        ev.header.forEach(item => {
          this.tableHeader1.forEach(res => {
            if (res.label === item) {
              this.tableHeaders.push(res)
            }
          })
        })
        this.tableHeader1 = this.tableHeaders
      } else if (ev.fname === '筛选方案') {
        this.tableHeader1 = this.oldTabHeader1
      }
    }
  }
}
